import { addUrlApi, cancelWhiteUrlApi, cancelWhiteUrlByIdApi } from "api/evaluateApi";
/**
 * @函数功能:分页基础数据
 * @参数输入:
 * @函数返回:
 */
export const paginationMixin = {
  data() {
    return {
      page: 1, //初始化显示第一页数据
      pageSize: 10, //默认显示页面数量
      pageSizes: [10, 20, 50], //页面数据数组，展示的选择每页显示个数的选项
      totalSize: 0, //总条数
      currentPage: 1,
      layout: "total ,sizes,prev,pager,next,jumper",
    };
  },
  methods: {
    //解决点击搜索或者重置的时候 改成第一页
    paginationReset() {
      this.page = 1;
      this.currentPage = 1;
    },
  },
};

/**
 * @函数功能:加白和取消加白
 */
export const addWhiteMixin = {
  data() {
    return {
      selectUrlRow: {}, //点击加白和取消加白
    };
  },
  methods: {
    //点击加白和取消加加白
    //params:sign:string add(加白) cancelById(通过白名单urlID)取消加白
    //params:datasec:string  datasec_report:审计报告 datasec_monitor:监控报告
    addWhiteHandler(sign, datasec, id) {
      let con =
        sign == "add" ? "加白之后该指标不再审计该项数据，确定加白么？" : "取消加白之后该指标继续审计，确定取消加白么？";
      let title = sign == "add" ? "加白" : "取消加白";
      let htmlStr = `<p style='margin-bottom:10px'>${con}</p><div><span style='color:red'>*</span>备注：</div>`;
      this.$prompt(htmlStr, title, {
        // type: "warning",
        dangerouslyUseHTMLString: true,
        confirmButtonText: "确定",
        cancelButtonText: "取消",
        inputType: "textarea",
        inputPattern: /\S/,
        inputErrorMessage: "请输入",
      }).then(({ value }) => {
        if (value.length > 200) {
          this.message.warning({ message: "内容不能超过200个字符" });
          return;
        }
        //加白
        if (sign === "add") {
          this.addWhiteUrl(value, datasec);
        } else if (sign === "cancelById") {
          this.cancelWhiteUrlById(value, id);
        } else {
          this.cancelWhiteUrl(value, datasec);
        }
      });
    },
    //加白
    addWhiteUrl(remark, datasec) {
      addUrlApi({
        dataId: this.selectUrlRow.dataId,
        id: this.selectUrlRow.itemId,
        host: this.selectUrlRow.host,
        url: this.selectUrlRow.url,
        sourceType: datasec || "datasec_report",
        remark: remark,
      }).then((res) => {
        this.message.state(res);
        this.getRiskUrls();
      });
    },
    //取消加白
    cancelWhiteUrl(remark, datasec) {
      cancelWhiteUrlApi({
        dataId: this.selectUrlRow.dataId,
        id: this.selectUrlRow.itemId,
        host: this.selectUrlRow.host,
        url: this.selectUrlRow.url,
        sourceType: datasec || "datasec_report",
        remark: remark,
      }).then((res) => {
        this.message.state(res);
        this.getRiskUrls();
      });
    },
    //取消加白 在资产中心==》资产详情==》敏感url(tab界面)加白指标使用了
    cancelWhiteUrlById(remark, id) {
      cancelWhiteUrlByIdApi({ id: id, remark: remark }).then((res) => {
        this.message.state(res);
        this.initTableData();
      });
    },
  },
};
